# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/7 23:11
# @Author   : Robot-Zsj
"""
description:

input
abc1 A
xyz B

output
abc1
"""


def getResult():
    dic = {}
    while True:
        try:
            player, gesture = input().split()

            if gesture < 'A' or gesture > 'C':
                print('NULL')
                return
            dic.setdefault(gesture, [])
            dic[gesture].append(player)
        except:
            break
    kinds = len(dic)

    if kinds == 1 or kinds == 3:
        print('NULL')
    else:
        ans = None
        if 'A' not in dic:
            ans = dic['B']
        elif 'B' not in dic:
            ans = dic['C']
        else:
            ans = dic['A']

        ans.sort()
        for an in ans:
            print(an)


getResult()
